<script setup>
import { onMounted, ref, toRefs } from 'vue'
import useUserStore from '@/pinia/userInfo'
import { getLatelyList, delLately } from '@/api/user'
import GameList from '../console/GameList.vue'
const userStore = useUserStore()
const { currentProvider } = toRefs(userStore)
const gameList = ref([])
onMounted(async () => {
  const { data } = await getLatelyList({
    provider_id: currentProvider.value.provider_id
  })
  gameList.value = data.list || []
})

// 删除最近游戏
const delList = async (item, index) => {
  try {
    await delLately({
      provider_id: item.provider_id,
      content_id: item.content_id
    })
    gameList.value.splice(index, 1)
  } catch (err) {
    console.log(err)
  }
}
</script>
<template>
  <div class="game-list">
    <GameList :_game-list="gameList" type="history" @delList="delList"></GameList>
  </div>
</template>
